#include <iostream>

/*
绝对不要在构造和析构中调用virtual函数。
不会执行 child的Log()
*/
namespace baseDemo {


class BaseClass {
public:
    BaseClass(){
        init();
    };

    void init() {
        Log();
    }

    ~BaseClass(){
        std::cout << "~BaseClass() Log()" << std::endl;
    };

    virtual void Log() const {
        std::cout << "BaseClass() Log()" << std::endl;
    }

};

class Child : public BaseClass {
public:
    virtual void Log() const override {
        std::cout << "Child Log()" << std::endl;
    }
};

class GrandSon : public Child {
public:
    virtual void Log() const override {
        std::cout << "GrandSon Log()" << std::endl;
    }
};

int main(void)
{
    Child a;  //不会执行 child的Log()
    GrandSon b; //不会执行 child或GrandSon的Log()
    return 0;
}
}
